/**
 * Created by guodong on 2017/11/02.
 */
'use strict';
angular.module('app')
    .controller('reportController', [ '$rootScope', '$scope', '$http', '$state','$timeout',
        function($rootScope, $scope, $http, $state, $timeout) {
            $scope.title = '举报管理';
            $scope.searchParams = { };
            $scope.loading = false;
            $scope.param={};
            $scope.search = function () {
                $scope.loading = true;
                $.ajax({
                    url : $scope.app.project_name+'/reportManage/report/list',
                    data: $scope.searchParams
                }).then(function(result) {
                    console.log(result);
                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;
                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }

            $scope.searchRe = function () {
                $scope.loading = true;
                $scope.searchParams.pageNum = 1;
                $.ajax({
                    url : $scope.app.project_name+'/reportManage/report/list',
                    data: $scope.searchParams
                }).then(function(result) {

                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;
                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }

            $scope.search();

            $scope.clearSearch = function() {
                $scope.searchParams= { };
                $scope.search();
            }

            // 翻页
            $scope.pagination = function (pageNo) {
                $scope.searchParams.pageNum=pageNo;
                $scope.search();
            };

            // 删除
            $scope.deleteById=function (id) {
                $scope.alertModel({
                    text:'确定删除？',
                    btnCancel:true,
                    resCode:"10000"
                }).then(function(){
                    $.ajax({
                        url : $scope.app.project_name+'/reportManage/report/delete',
                        data: {id:id}
                    }).then(function(result) {
                        $scope.loading = false;
                        $scope.alertModal({"content":"操作成功"});
                        if (result.httpCode != 200) {
                            $scope.alertModal(result.msg);
                        }
                        $scope.search();
                    });
                })
            }

            $scope.oper = function (id,$event) {

                $.ajax({
                    url : $scope.app.project_name+'/reportManage/report/banEnable',
                    data: {id:id,enable:$event.target.checked?'Y':'N'}
                }).then(function(result) {
                    $scope.loading = false;
                    $scope.alertModal({"content":"操作成功"});
                    if (result.httpCode != 200) {
                        $scope.alertModal(result.msg);
                    }
                    $scope.search();
                });
            }

            //查询举报列表下拉信息
            $scope.changeParent = function () {
                $.ajax({
                    url : $scope.app.project_name+ '/reportManage/report/getReportselect',
                    data: { }
                }).then(function(result) {
                    if (result.httpCode == 200) {
                        console.log(result.data);
                        $scope.reportListName = result.data;
                        console.log(result.data[0].reportName);
                    } else {
                        $scope.msg = result.msg;
                    }
                });


                $scope.searchRe();
            }

            $scope.changeParent();

            // 举报描述鼠标移入的动作
            $scope.introduction = [];
            $scope.preview = function(introduction){
                var showDiv = document.getElementById('showDiv');
                showDiv.style.left = event.clientX;
                showDiv.style.top = event.clientY;
                showDiv.style.display = 'block';
                showDiv.innerHTML = introduction;
            }
            // 举报描述鼠标移出的动作
            $scope.outHide = function(){
                var showDiv = document.getElementById('showDiv');
                showDiv.style.display = 'none';
                showDiv.innerHTML = '';
            }

        } ]);